<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib uri="http://agi.corp.org/authz" prefix="authz"%>
<%@ page import="com.verisette.ncos.common.PrivConst"%>
<%@ page import="com.verisette.ncos.common.ProjectConstant"%>
<%@page import="org.corp.agi.service.bean.UserBean"%>
<%@page import="org.corp.agi.web.constant.WebConstant"%>
<%@ taglib prefix="cd" uri="/WEB-INF/tld/commondisplay-tag.tld"%>

<%
	UserBean user = (UserBean)request.getSession(false).getAttribute(WebConstant.SESSION_USERBEAN_KEY);
	pageContext.setAttribute("userRequest", user);
%>

<!-- body content -->
<!-- / body content -->
<s:form id="mainForm" action="changePassword-changePassword.htm" method="post" >
<table width="722" border="0" cellpadding="0" cellspacing="0" class="bg3">
	<tr>
		<td width="50%" valign="top">
			<table width="300" height="40" border="0" align="left" cellpadding="0" cellspacing="0">
				<tr>
        			<td class="font02">เปลี่ยนรหัสผ่าน</td>
				</tr>
    		</table>
		</td>
    	<td width="50%">
			<table width="250" height="124" border="0" align="left" cellpadding="0" cellspacing="0">
       			<tr>
         			<td height="34">&nbsp;</td>
       			</tr>
       			<tr>
					<td height="30">
         				<span class="font07_1">คุณ
             			<label for="textfield12" class="font07_1"></label>
         				</span>
         				<label for="textfield12" class="font07_1">${ sessionScope[request.SESSION_USERBEAN_KEY].uspFname }&nbsp;${ sessionScope[request.SESSION_USERBEAN_KEY].uspLname }</label>
         			</td>
         		</tr>
       			<tr>
         			<td height="30" class="font07"><label for="textfield13"></label></td>
         		</tr>
       			<tr>
         			<td height="30"><input name="button" type="button" id="button" value="ออกจากระบบ" onclick="window.location='${ request.appBase }/accesscontrol/logout.htm';" /></td>
         		</tr>
			</table>
    	</td>
	</tr>
	<tr>
    	<td colspan="2">
    		<table width="400" border="0" align="center" cellpadding="0" cellspacing="0">
      			<tr>
        			<td><span class="font07">1. กรอกข้อมูล username และ password เก่า และ password ใหม่ </span></td>
      			</tr>
      			<tr>
        			<td><span class="font07">2. คลิกปุ่ม บันทึก เพื่อยืนยันการเปลี่ยนรหัสผ่าน</span></td>
      			</tr>
      			<tr>
        			<td>&nbsp;</td>
      			</tr>
    		</table>
			<table width="400" bgcolor="#707070" border="0" align="center" cellpadding="3" cellspacing="0">
      			<tr>
        			<td width="172" height="40" class="font04">ชื่อผู้ใช้งาน * :</td>
        			<td width="208" class="font01">${ sessionScope[request.SESSION_USERBEAN_KEY].uspUserName }</td>
      			</tr>
      			<tr>
        			<td height="40" class="font04">รหัสผ่านเดิม* :</td>
        			<td>
        				<input name="oldPassword" type="password" class="form_user_pass" id="oldPassword">
                		<br/><span id="errorsDiv_oldPassword"></span>
                	</td>
      			</tr>
      			<tr>
        			<td height="40" class="font04">รหัสผ่านใหม่* :</td>
        			<td>
        				<input name="newPassword" type="password" class="form_user_pass" id="newPassword">
                		<br/><span id="errorsDiv_newPassword"></span>
                	</td>
      			</tr>
      			<tr>
        			<td height="40" class="font04">ยืนยันรหัสผ่านใหม่* :</td>
        			<td>
        				<input name="confirmPassword" type="password" class="form_user_pass" id="confirmPassword">
                		<br/><span id="errorsDiv_confirmPassword"></span>
                	</td>
      			</tr>
    		</table>
      		<table width="250" height="30" border="0" align="center" cellpadding="0" cellspacing="0">
      			<tr>
					<td class="font06" style="color: red;">
						<div id="alert" class="alert" style="display: none;"></div>
					</td>
      			</tr>
        		<tr>
          			<td height="30" align="center">
            			<input name="button" type="button" id="button2" value="บันทึก" onclick="onClickSave()"> &nbsp;
            			<input name="button" type="button" id="button2" value="ยกเลิก" onclick="window.location='${appBase}/accesscontrol/main-init.htm'">
            		</td>
        		</tr>
      		</table>
      	</td>
	</tr>
</table>
</s:form>
<script>
function onClickSave(){
	var form = document.forms['changePassword-changePassword.htm'];
	
    var rules=new Array();
    rules[1]='oldPassword:Old Password|required';
    rules[2]='newPassword:New Password|required';
    rules[3]='confirmPassword:Confirm New Password|required';
    rules[4]='confirmPassword:Confirm New Password|equal|'+$j("#newPassword").val() +'|กรุณาระบุ Confirm New Password ให้ตรงกับ New Password';
	
    if (yav.performCheck('mainForm', rules, 'inline')){
		$j("#mainForm").submit();
	}
}

function onClickBack(){
    $j("#mainForm").attr("action","main-init.htm"); 
  	$j("#mainForm").submit();
}

function showResponse(responseText, statusText, isErrorPage) {
	//error/warning/info
	eval( "var o = " + responseText + "" );
	var status = o.status;
	var content = "";
	if (o.messageList != null) {
		for (var i=0; i<o.messageList.length; i++) {
			//content += "<strong>" + o.messageList[i].messageCode + "</strong>"+" : "+o.messageList[i].messageText+"<br/>";
			content += o.messageList[i].messageText+"<br/>";
		}
	}

	$j("#alert").html(content).show();
	$j("#username").focus();
}
showResponse('{'
		+'"status":"${sessionScope.SESSION_STATUS_KEY}",'
		+'"messageList":${cd:escJS(sessionScope.SESSION_MESSAGE_KEY)}}',
		''); 
</script>